import { IDispose } from "../../../../../com/gengine/core/IDispose";
import { FishingScene } from "./FishingScene";
import { FishingGlobal } from "./FishingGlobal";
import { BitmapDataPool } from "../../../../common/pools/BitmapDataPool";
import { HookAutoSwingController } from "./ObjController/HookAutoSwingController";
import { Hook } from "./Obj/Hook";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { FishDispatcher } from "./FishDispatcher";
import { FishingEventName } from "./FishingEventName";
import { DataEvent } from "../../../events/DataEvent";
import { FishFactory } from "./FishFactory";
import { FishDirection } from "./defin/FishDirection";
//class FishingGame
    
    export  class FishingGame /* flash.display.Sprite */ implements IDispose
    {
        constructor(arg1: number, arg2: number)
        {
            
            FishingScene.AREAWIDTH = arg1;
            FishingScene.AREAHEIGHT = arg2;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc3=null;
            this._fishScene = new FishingScene();
            this.addChild(this._fishScene);
            FishingGlobal.scene = this._fishScene;
            var loc1=new Object /* flash.display.Bitmap */(BitmapDataPool.getMaskBitmapData(FishingScene.AREAWIDTH, FishingScene.AREAHEIGHT));
            this.addChild(loc1);
            this._fishScene.mask = loc1;
            var loc2=new HookAutoSwingController();
            loc3 = new Hook(loc2);
            loc3.x = FishingScene.AREAWIDTH / 2;
            loc3.y = 0;
            this._fishScene.addObject(loc3);
            this._timer = new SecTimer(1);
            this._timer.addListener(TimerType.ENTERFRAME, this.onEnterFrame);
            FishDispatcher.addEventListener(FishingEventName.FishSquib, this.onFishSquib);
            return;
        }

        /* internal  */onFishSquib(arg1: DataEvent): void
        {
            var loc1=arg1.data as Object /* flash.geom.Point */;
            this._fishScene.addEffect(FishFactory.getSquibPlayer(), loc1.x, loc1.y);
            return;
        }

        /* internal  */onEnterFrame(arg1: SecTimer): void
        {
            var loc1=FishFactory.randomObj();
            if (loc1.horizontalDirection != FishDirection.LEFT) 
            {
                loc1.x = -1 * loc1.width;
            }
            else 
            {
                loc1.x = FishingScene.AREAWIDTH;
            }
            loc1.y = loc1.minDepth + Math.random() * (loc1.maxDepth - loc1.minDepth);
            this._fishScene.addObject(loc1);
            return;
        }

        public start(): void
        {
            this._timer.start();
            this._fishScene.start();
            return;
        }

        public stop(): void
        {
            this._timer.stop();
            this._fishScene.stop();
            return;
        }

        public dispose(arg1: Boolean=true): void
        {
            this._timer.stop();
            this._fishScene.dispose();
            this.removeChild(this._fishScene);
            this._fishScene = null;
            this._timer = null;
            return;
        }

        /* internal */ /* var */_fishScene: FishingScene;

        /* internal */ /* var */_timer: SecTimer;
    }
